package com.lyx.crm.controller;

import com.lyx.crm.base.BaseController;
import com.lyx.crm.base.ResultInfo;
import com.lyx.crm.query.CustomerQuery;
import com.lyx.crm.service.CustomerService;
import com.lyx.crm.vo.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @Package: com.lyx.crm.controller
 * @ClassName: CustomerController
 * @Author: lyx
 * @CreateTime: 2021/10/3 16:38
 * @Description:
 */
@Controller
@RequestMapping("customer")
public class CustomerController extends BaseController {

    @Autowired
    private CustomerService customerService;


    @RequestMapping("list")
    @ResponseBody
    public Map<String, Object> QueryCustomerByParams(CustomerQuery customerQuery) {

        return customerService.queryCustomerByParams(customerQuery);

    }

    @RequestMapping("index")
    public String toCustomerPage() {
        return "customer/customer";
    }

    /**
     * 转到更新/添加页面
     *
     * @param customerId
     * @return
     */
    @RequestMapping("toAddOrUpdateCustomerPage")
    public String toAddOrUpdateCustomerPage(Integer customerId) {
        if (customerId != null) {

        }
        return "customer/add_update";
    }


    /**
     * 添加客户操作
     *
     * @param customer
     * @return
     */
    @ResponseBody
    @RequestMapping("add")
    public ResultInfo addCustomer(Customer customer) {

        customerService.addCustomer(customer);

        return success("用户添加成功");
    }

}
